<?php
session_start();

require_once('../configs/common.php'); 	 
require_once(CONFIGS_DIR."db_connect.php");
require_once(MODELS_DIR.'Comments.class.php');
require_once(MODELS_DIR.'Likes.class.php');

if ($_POST['action']=="get_video_comments_and_likes")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 $response=array();
	 $response['comments'] = Comments::getVideoComments($request_data['videos_link_name']);	
	 $response['likes'] = Likes::getVideoLikesCount($request_data['videos_link_name']);		 
	 
	 header('Content-Type: application/json');
	 echo json_encode($response);
}

if ($_POST['action']=="get_photo_comments_and_likes")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 $response=array();
	 $response['comments'] = Comments::getPhotoComments($request_data['photos_link_name']);	
	 $response['likes'] = Likes::getPhotoLikesCount($request_data['photos_link_name']);	
	 
	 header('Content-Type: application/json');
	 echo json_encode($response);
}

if ($_POST['action']=="insert_video_comment")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 Comments::InsertVideoComments($request_data['videos_link_name'], $request_data['text']);	
	 $response=array();
	 $response['user_name'] = $_SESSION['user_name'];
	 $response['date'] = time();
	 $response['text'] = $request_data['text'];
	 
	 header('Content-Type: application/json');
	 echo json_encode($response);
}

if ($_POST['action']=="insert_photo_comment")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 Comments::InsertPhotoComments($request_data['photos_link_name'], $request_data['text']);	
	 $response=array();
	 $response['user_name'] = $_SESSION['user_name'];
	 $response['date'] = time();
	 $response['text'] = $request_data['text'];
	 
	 header('Content-Type: application/json');
	 echo json_encode($response);
}

if ($_POST['action']=="add_video_like")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 $response=array();
	 $response['likes'] = Likes::add_video_like($request_data['videos_link_name'], $_SERVER['REMOTE_ADDR'], $request_data['like_status']); 
	 
	 header('Content-Type: application/json');
	 echo json_encode($response);
}

if ($_POST['action']=="add_photo_like")
{
	 $request_data=safe_var_Array(json_decode($_POST['data']), true);
	 $response=array();
	 $response['likes'] = Likes::add_photo_like($request_data['photos_link_name'], $_SERVER['REMOTE_ADDR'], $request_data['like_status']); 
	 
	 header('Content-Type: application/json');
	 echo json_encode($response);
}


